package com.micromall.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.micromall.common.base.BaseController;
import com.micromall.common.utils.PageInfo;
import com.micromall.model.BusiOrderItem;
import com.micromall.service.IBusiOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 订单项表  前端控制器
 * </p>
 * @author Dante Fung
 * @since 2017-07-26
 */
@Controller
@RequestMapping("/busiOrderItem")
public class BusiOrderItemController extends BaseController {
    
    @Autowired private IBusiOrderItemService busiOrderItemService;
    
    @GetMapping("/manager")
    public String manager() {
        return "admin/busiOrderItem/busiOrderItemList";
    }


    @PostMapping("/dataGrid")
    @ResponseBody
    public PageInfo dataGrid(BusiOrderItem busiOrderItem, Integer page, Integer rows, String sort,String order) {
        EntityWrapper<BusiOrderItem> ew = new EntityWrapper<BusiOrderItem>();
        ew.setEntity(busiOrderItem);
        Page<BusiOrderItem> pages = getPage(page, rows, sort, order);
        pages = busiOrderItemService.selectPage(pages,ew);
        return pageToPageInfo(pages);
    }
    
    /**
     * 添加页面
     * @return
     */
    @GetMapping("/addPage")
    public String addPage() {
        return "admin/busiOrderItem/busiOrderItemAdd";
    }

    /**
     * 添加
     * @param 
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Object add(BusiOrderItem busiOrderItem) {
        boolean b = busiOrderItemService.insert(busiOrderItem);
        if (b) {
            return renderSuccess("添加成功！");
        } else {
            return renderError("添加失败！");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        BusiOrderItem busiOrderItem = new BusiOrderItem();
        busiOrderItem.setId(id);
        boolean b = busiOrderItemService.updateById(busiOrderItem);
        if (b) {
            return renderSuccess("删除成功！");
        } else {
            return renderError("删除失败！");
        }
    }

    /**
     * 编辑
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(Model model, Long id) {
        BusiOrderItem busiOrderItem = busiOrderItemService.selectById(id);
        model.addAttribute("busiOrderItem", busiOrderItem);
        return "admin/busiOrderItem/busiOrderItemEdit";
    }

    /**
     * 编辑
     * @param 
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public Object edit(BusiOrderItem busiOrderItem) {
        boolean b = busiOrderItemService.updateById(busiOrderItem);
        if (b) {
            return renderSuccess("编辑成功！");
        } else {
            return renderError("编辑失败！");
        }
    }
    
}
